package com.ybcj.mapper;

import com.ybcj.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    // 根据id删除记录
    @Delete("delete from emp where id = #{id}")
    Integer deletedEmpbyId(Integer id);

    // 批量删除
    Integer deletedEmp(List<Integer> ids);

    // 新增员工
    @Options(useGeneratedKeys = true, keyProperty = "id")   // 插入成功,返回主键
    @Insert("insert into emp(username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +
            "values(#{username}, #{password}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
    Integer addEmp(Emp emp);


    // 修改员工
    @Update("update emp set username = #{username}, password = #{password}, name = #{name}, gender = #{gender}, image = #{image}," +
            "job = #{job}, entrydate = #{entrydate}, dept_id = #{deptId}, create_time = #{createTime}, update_time = #{updateTime}" +
            "where id = #{id}")
    Integer modiEmp(Emp emp);


    // 修改员工  xmp映射
    Integer modiEmpOth(Emp emp);


    // 根据id获取员工信息
//    @Select("select * from emp where id = #{id}")
    // 手动映射列名
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")})
    Emp getEmpById(Integer id);

    // 条件查询
//    @Select("select * from emp where name like '%${name}%' and entrydate between #{begin} and #{end}")
//    @Select("select * from emp where name like concat('%', #{name}, '%') and entrydate between #{begin} and #{end}")
    List<Emp> listEmp (String name, Integer gender,LocalDate begin,  LocalDate end);

}
